package org.pointex.common.service.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.pointex.common.dao.BaseDAO;
import org.pointex.common.model.PageEntity;
import org.pointex.common.model.PagingResult;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 
 * @ClassName: BaseServiceImpl
 * @Description: 业务层实现类-实现处理业务逻辑方法
 * @author Kenny_Z' szqiuk@gmail.com
 * @date 2016年10月22日 下午11:01:46
 * 
 * @param <T>
 * @param <PK>
 */
public class BaseServiceImpl<T, PK extends Serializable> implements BaseDAO<T, Serializable> {

	@Autowired
	private BaseDAO<T, Serializable> baseDAO;

	public void setBaseDAO(BaseDAO<T, Serializable> baseDAO) {
		this.baseDAO = baseDAO;
	}
	
	public int deleteByPrimaryKey(Integer id) {
		int result = 0;
		try {
			if (id != null && id > 0) {
				result = baseDAO.deleteByPrimaryKey(id);
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public int insert(T record) {
		int result = 0;
		try {
			if (record != null) {
				result = baseDAO.insert(record);
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public int insertSelective(T record) {
		int result = 0;
		try {
			if (record != null) {
				result = baseDAO.insertSelective(record);
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public T selectByPrimaryKey(Integer id) {
		try {
			if (id != null && id > 0) {
				return baseDAO.selectByPrimaryKey(id);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public int updateByPrimaryKeySelective(T record) {
		int result = 0;
		try {
			if (record != null) {
				result = baseDAO.updateByPrimaryKeySelective(record);
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public int updateByPrimaryKey(T record) {
		int result = 0;
		try {
			if (record != null) {
				result = baseDAO.updateByPrimaryKey(record);
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public int insert_(T entity) {
		int result = 0;
		try {
			if (entity != null) {
				result = baseDAO.insert_(entity);
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public int update(T entity) {
		int result = 0;
		try {
			if (entity != null) {
				result = baseDAO.update(entity);
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public int updateParam(Map param) {
		int result = 0;
		try {
			if (param.size() > 0 && param != null) {
				result = baseDAO.updateParam(param);
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public int delete(Serializable primaryKey) {
		int result = 0;
		try {
			if (primaryKey != null) {
				result = baseDAO.delete(primaryKey);
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public int deleteParam(Map param) {
		int result = 0;
		try {
			if (param.size() > 0 && param != null) {
				result = baseDAO.deleteParam(param);
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public int truncate() {
		int result = 0;
		try {
			result = baseDAO.truncate();
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public int count() {
		int result = 0;
		try {
			result = baseDAO.count();
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public int count(Object param) {
		int result = 0;
		try {
			if (param != null) {
				result = baseDAO.count(param);
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public T get(Serializable primaryKey) {
		if (primaryKey != null) {
			return baseDAO.get(primaryKey);
		}
		return null;
	}

	public List<T> select() {
		List<T> list = null;
		try {
			list = baseDAO.select();
			return list;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	public List<T> selectParam(Map param) {
		List<T> list = null;
		try {
			if (param.size() > 0 && param != null) {
				list = baseDAO.selectParam(param);
			}
			return list;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	public PagingResult<T> selectPagination(PageEntity param) {
		PagingResult<T> result = null;
		try {
			if (param != null) {
				result = baseDAO.selectPagination(param);
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public int insertBatch(List<T> list) {
		int result = 0;
		try {
			if (list.size() > 0 && list != null) {
				result = baseDAO.insertBatch(list);
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public int updateBatch(List<T> list) {
		int result = 0;
		try {
			if (list.size() > 0 && list != null) {
				result = baseDAO.updateBatch(list);
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	
	public int deleteBatch(List<Serializable> list) {
		int result = 0;
		try {
			if (list.size() > 0 && list != null) {
				result = baseDAO.deleteBatch(list);
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
}
